package cn.wjzhang.middle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

/**
 * ========================
 * 中间件启动类
 *
 * @author wjzhang
 * @version v1.0
 * ========================
 * @date 2023/6/21 9:30
 */
@SpringBootApplication(scanBasePackages = {"cn.wjzhang"})
@Slf4j
@EnableDiscoveryClient(autoRegister = true) // 本地启动时修改为false
public class MiddleApplication {

    public static void main(String[] args) throws UnknownHostException {

        ApplicationContext ctx = SpringApplication.run(MiddleApplication.class, args);
        Environment env = ctx.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = Objects.isNull(env.getProperty("server.servlet.context-path")) ? "" : env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n\t" +
                "中间件 is running! Access URL:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "\n\t" +
                "api Doc: \t\thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");

    }

}
